﻿//  Author:
//       Daniel Großer <olav.daniel.grosser@googlemail.com>
//  
//  Copyright (c) 2012 Copyright (C) 2012 by Daniel Großer. This Code is under GNU LGPL 3.0
// 
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
// 
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
// 
//  You should have received a copy of the GNU Lesser General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;

namespace Beauty
{
    /// <summary>
    /// This is the basic attribute for properties that form the grammar of the language.
    /// The grammar of a language typically consists of the following types of grammar parts:
    /// <list type="ordered">
    /// <item>Keywords (see <see cref="KeywordAttribute"/>)</item>
    /// <item>Delimeters (see <see cref="DelimeterAttribute"/>)</item>
    /// <item>Literals/Identifiers (see <see cref="RegExTerminalAttribute"/>)</item>
    /// <item>Productions (see <see cref="ProductionAttribute"/>)</item>
    /// </list>
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, AllowMultiple=false, Inherited=true)]
    public abstract class GrammarEntityAttribute : Attribute
    {
        /// <summary>
        /// This can be set to true if the property and thus the rule is optional.
        /// This can be used to implement rules like:
        /// A => B C?
        /// A => B* C
        /// ...
        /// </summary>
		public bool IsOptional {
			get;
			set;
		}
		
		private string _DependsOn;
		/// <summary>
		/// Sets the name of the property this rule depends on.
		/// This member is used to enable the rule-grouping feature.
		/// The rule induced by this attribute will not be parsed
		/// if the rule denoted by the value of the DependsOn - property
		/// has not already been parsed. This brings some context-sensitivity
		/// to the grammars that can be recognized. However, only
		/// backward-references are useful.
		/// 
		/// Setting this property automatically sets IsOptional to true,
		/// so do not use this property in conjunction with the
		/// <see cref="IsOptional"/> member.
		/// </summary>
		/// <value>
		/// The rule that this rule depends on.
		/// </value>
		public string DependsOn
		{
			get
			{
				return _DependsOn;
			}
			set
			{
				_DependsOn = value;
				if (!string.IsNullOrEmpty(value))
					IsOptional = true;
			}
		}
    }
}
